<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop" :style="pagetop">
          <template>
              <div style="width: 100%">
                  <div style="float: left; width: 50%">
                      <table style="font-size: 12px" class="table1style">
                          <tr>
                              <td style="width: 30px">条形码</td>
                              <td>
                                  <el-input style="width: 250px" @keyup.enter.native="ScanBarcode($event)" v-model="barcode" @focus="HightlightPos()" id="barcodediv"></el-input>
                              </td>
                              <td :hidden="ck_auto_dept">目标科室</td>
                              <td :hidden="ck_auto_dept">
                                  <rm-ddl-common datatype="dept" dataname="科室" v-model="recieve_dept" width="150px" :disabled="!is4402"></rm-ddl-common>
                              </td>
                              <td :hidden="auto_dept">标本数量</td>
                              <td :hidden="auto_dept">
                                  <el-input style="width: 50px" v-model="specimen_number" :disabled="true"></el-input>
                              </td>
                          </tr>

                          <tr :hidden="!is4401">
                              <td style="width: 30px">送出部门</td>
                              <td>
                                  <rm-ddl-common datatype="dept" dataname="科室" v-model="send_dept" width="250px"></rm-ddl-common>
                              </td>
                              <td colspan="2" style="text-align: left">
                                  <el-checkbox v-model="ck_auto_dept" @change="auto_dept_changeEvent">自动识别接收科室</el-checkbox>
                              </td>
                              <td style="text-align: left; width: 130px">
                                  混样条码：【<span style="color: blue; font-weight: bold">{{ mixbarcodecnt }}</span
                                  >】个
                              </td>
                              <td style="text-align: left">
                                  共包含【<span style="color: blue; font-weight: bold">{{ mixpeoplecnt }}</span
                                  >】人
                              </td>
                          </tr>
                          <tr>
                              <td>送出人</td>
                              <td>
                                  <rm-ddl-common datatype="userinfo" dataname="用户" v-model="send_user" width="250px"></rm-ddl-common>
                              </td>
                              <td>运送人</td>
                              <td>
                                  <rm-ddl-common style="display: inline-block" @change="senduserinfochange" datatype="userinfo" dataname="用户" v-model="senduserinfoval" width="150px" key="userno" :onlyshow="sendusermustlogin == '1'" :readonly="true"></rm-ddl-common>
                                  <el-button v-if="sendusermustlogin == '1'" @click="loginUser()">登陆</el-button>
                              </td>
                              <td style="text-align: left">
                                  普通条码：【<span style="color: blue; font-weight: bold">{{ combarcodecnt }}</span
                                  >】个
                              </td>
                          </tr>
                      </table>
                  </div>
                  <div style="float: left; width: 50%; margin-top: 70px">
                      <div>
                          <table style="float: right">
                              <tr>
                                  <td style="text-align: right">
                                      <el-button icon="el-icon-delete" @click.native="btnDelete">删除</el-button>
                                      <el-button icon="el-icon-position" @click="true4401_sendEvent">送出</el-button>
                                      <el-button icon="el-icon-delete-solid" @click="BtnClear">清除</el-button>
                                      <el-button icon="el-icon-position" @click="showbatchwindow">批量获取标本</el-button>
                                      <el-button icon="el-icon-printer" v-has="'PPRINT'" @click="btnPrint_click()">打印</el-button>
                                      <el-button icon="el-icon-printer" v-show="loginutype =='G'" @click="RptStyleSetting()">打印设计</el-button>
                                      <el-button icon="el-icon-printer" @click="BtnPageCodePrint">重打包条码</el-button>
                                      <el-button icon="el-icon-search" @click="BtnHistoryQuery">打包记录</el-button>
                                  </td>
                              </tr>
                          </table>
                      </div>
                  </div>
              </div>
          </template>
      </div>
      <div class="pagecenter" :style="pagecenter">
          <div class="middle-left" :hidden="!auto_dept">
              <!-- <div style="float: left">
                  <div style="float: left; width: 150px; text-align: left">
                      <el-button icon="el-icon-position" @click="trans_sendEvent">按包送出</el-button>
                  </div>
                  <div style="float: left; width: 150px; text-align: right">
                      <el-button icon="el-icon-delete-solid" style="margin-right: 0px" @click="trans_deleteEvent">按包清除</el-button>
                  </div>
              </div>
              <div style="position: absolute; top: 30px; bottom: 0px; width: 300px; left: 0px"> -->
              <vxe-table :data.sync="trans_data" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="trans_table" resizable row-id="his_interface_table_rowid" show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" @current-change="trans_table_changeEvent" :radio-config="{ trigger: 'row' }" header-align="center">
                  <vxe-table-column type="selection" width="35" align="center"></vxe-table-column>
                  <vxe-table-column field="packagebarcode" sortable title="传送条码" width="100"></vxe-table-column>
                  <vxe-table-column field="recievedeptname" sortable title="接收部门" width="80"></vxe-table-column>
                  <vxe-table-column field="recievedeptno" sortable title="接收部门" width="80" v-if="false"></vxe-table-column>
                  <vxe-table-column field="samplecount" sortable title="标本数量" width="80"></vxe-table-column>
                  <vxe-table-column field="last_barcode" sortable title="最后一个条码" width="120"></vxe-table-column>
                  <vxe-table-column field="last_user" sortable title="最后一个病人姓名" width="150"></vxe-table-column>
                  <template v-slot:fix>
                      <div style="font-size: 20px; padding-left: 3px; background-color: #fff; overflow: auto">
                          <span>
                              <span style="color: blue; font-weight: bold; margin-left: 3px; display: inline-block; padding: 2px 4px">合计:{{ maintotal }}</span>
                          </span>
                      </div>
                  </template>
              </vxe-table>
              <!-- </div> -->
          </div>
          <div :style="middle_center">
              <vxe-table :data.sync="master_data_show" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="master_table" resizable show-overflow size="mini" stripe :row-class-name="RowClassName_masterTable" show-header-overflow :optimization="{ animat: false }" :key="drawagain" @current-change="master_table_changeEvent" :selectConfig="{ checkMethod }" header-align="center" @cell-dblclick="delete_master_data">
                  <!-- <vxe-table-column type="selection" width="35" align="center"></vxe-table-column> -->
                  <vxe-table-column field="req_groupna" sortable title="分单类别" width="100"></vxe-table-column>
                  <vxe-table-column field="barcode" sortable title="条形码" width="100"></vxe-table-column>

                  <vxe-table-column field="pat_name" sortable title="病人姓名" width="120"></vxe-table-column>
                  <vxe-table-column field="mixcnt" sortable title="明细数" width="60"></vxe-table-column>
                  <vxe-table-column field="pat_sexname" sortable title="性别" width="40" align="center"></vxe-table-column>
                  <vxe-table-column field="pat_agestr" sortable title="年龄" width="80"></vxe-table-column>
                  <vxe-table-column field="specimen_name" sortable title="标本类型" width="100"></vxe-table-column>
                  <vxe-table-column field="req_statname" sortable title="状态" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="sample_items" sortable title="申请项目(描述)" width="200"></vxe-table-column>
                  <vxe-table-column field="send_dt" sortable title="送出时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="send_username" sortable title="送出人" width="100" align="center"></vxe-table-column>
                  <vxe-table-column field="sampled_dt" sortable title="采样时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="sampled_username" sortable title="采样人" width="100" align="center"></vxe-table-column>
                  <vxe-table-column field="create_username" sortable title="创建人" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="create_dt" sortable title="创建时间" width="120" align="center"></vxe-table-column>
                  <!-- <vxe-table-column field="recievedeptno" sortable title="接收部门" width="80"></vxe-table-column> -->
                  <vxe-table-column field="pat_typename" sortable title="病人来源" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="pat_no" sortable title="病历号" width="100"></vxe-table-column>
                  <!-- <vxe-table-column field="emer_flagname" sortable title="加急" width="80" ></vxe-table-column> -->
                  <vxe-table-column field="base_amount" sortable title="应收金额" width="100"></vxe-table-column>
                  <vxe-table-column field="req_deptname" sortable title="申请科室" width="100"></vxe-table-column>
                  <vxe-table-column field="req_docname" sortable title="申请医生" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="req_dt" sortable title="申请时间" width="120" align="center"></vxe-table-column>

                  <vxe-table-column field="print_dt" sortable title="打印(执行)时间" width="140" align="center"></vxe-table-column>
                  <vxe-table-column field="print_username" sortable title="打印(执行)人" width="120" align="center"></vxe-table-column>
                  <!-- <vxe-table-column field="print_count" sortable title="打印次数" width="60" align="center"></vxe-table-column> -->

                  <vxe-table-column field="prereport_dt" sortable title="预出报告时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="prereport_comm" sortable title="报告领取说明" width="150"></vxe-table-column>
                  <vxe-table-column field="pat_diag" sortable title="临床诊断" width="150"></vxe-table-column>
                  <vxe-table-column field="pat_id" sortable title="病人ID" width="120"></vxe-table-column>
                  <vxe-table-column field="inp_date" sortable title="入院日期" width="100"></vxe-table-column>
                  <vxe-table-column field="req_bedno" sortable title="床号" width="40"></vxe-table-column>
                  <vxe-table-column field="pat_cardno" sortable title="就诊卡号" width="120"></vxe-table-column>
                  <vxe-table-column field="pat_address" sortable title="地址" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_nation" sortable title="国籍" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_idcardno" sortable title="身份证号" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_phone" sortable title="联系电话" width="100"></vxe-table-column>
                  <vxe-table-column field="charge_dt" sortable title="计价时间" width="100"></vxe-table-column>
                  <vxe-table-column field="charge_username" sortable title="计价人" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="amount" sortable title="实收金额" width="100" align="right"></vxe-table-column>
                  <!-- <vxe-table-column field="chargeex_flag" sortable title="计价标志" width="100"></vxe-table-column> -->
                  <!-- <vxe-table-column field="alter_flag" sortable title="报警" width="80" ></vxe-table-column> -->
                  <!-- <vxe-table-column field="saleman" sortable title="销售人" width="60" align="center"></vxe-table-column> -->

                  <!-- <vxe-table-column field="req_comm" sortable title="医生备注" width="100"></vxe-table-column> -->
                  <!-- <vxe-table-column field="pat_birth" sortable title="生日" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_ageyear" sortable title="年龄岁数" width="100"></vxe-table-column>
                  <vxe-table-column field="inp_id" sortable title="住院标志" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_diag_icd" sortable title="诊断标准代码" width="150"></vxe-table-column> -->

                  <vxe-table-column field="charge_typeno" sortable title="费别代码" width="100"></vxe-table-column>
                  <vxe-table-column field="perform_dept" sortable title="执行科室" width="120"></vxe-table-column>
                  <!-- <vxe-table-column field="req_wardno" sortable title="病区代码" width="100"></vxe-table-column> -->
                  <vxe-table-column field="original_reqno" sortable title="原始单号" width="120"></vxe-table-column>
                  <!-- <vxe-table-column field="secrecy" sortable title="加密" width="100"></vxe-table-column>
                  <vxe-table-column field="other_stat" sortable title="其它状态" width="100"></vxe-table-column>
                  <vxe-table-column field="specimen_code" sortable title="标本类型代码" width="150"></vxe-table-column>
                  <vxe-table-column field="sample_detail" sortable title="标准备注说明" width="150"></vxe-table-column>
                  <vxe-table-column field="req_reason" sortable title="送检目的" width="100"></vxe-table-column>
                  <vxe-table-column field="pat_height" sortable title="身高(CM)" width="80"></vxe-table-column>
                  <vxe-table-column field="weight" sortable title="体重(KG)" width="80"></vxe-table-column>
                  <vxe-table-column field="abo_bldtype" sortable title="ABO血型" width="100"></vxe-table-column>
                  <vxe-table-column field="rh_bldtype" sortable title="RH血型" width="100"></vxe-table-column> -->
                  <template v-slot:fix>
                      <div style="font-size: 20px; padding-left: 3px; background-color: #fff; overflow: auto">
                          <span
                              ><span style="color: blue; font-weight: bold; margin-left: 3px; display: inline-block; padding: 2px 4px">合计:{{ total }}</span>
                              <span style="color: red; font-weight: bold; margin-left: 3px; display: inline-block; padding: 2px 4px">待送出:{{ rdysendtotal }}</span>
                          </span>
                      </div>
                  </template>
              </vxe-table>
          </div>
          <div class="middle-right">
              <vxe-table :data.sync="detail_data" :loading="detail_loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="his_interface_table" resizable row-id="his_interface_table_rowid" show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" :key="drawagain">
                  <vxe-table-column field="req" sortable title="序号" width="50"></vxe-table-column>
                  <vxe-table-column field="req_itemname" sortable title="项目名称" width="100"></vxe-table-column>
                  <vxe-table-column field="item_price" sortable title="实际价格" width="100"></vxe-table-column>
                  <vxe-table-column field="qty" sortable title="数量" width="60"></vxe-table-column>
                  <vxe-table-column field="amount" sortable title="金额" width="60"></vxe-table-column>
                  <vxe-table-column field="req_itemcode" sortable title="项目代码" width="100"></vxe-table-column>
                  <vxe-table-column field="his_itemcode" sortable title="HIS项目代码" width="140"></vxe-table-column>
                  <vxe-table-column field="his_recordid" sortable title="HIS记录号" width="120"></vxe-table-column>
                  <vxe-table-column field="combitemna" sortable title="所属组合" width="100"></vxe-table-column>
                  <vxe-table-column field="base_price" sortable title="基础价格" width="100"></vxe-table-column>
                  <vxe-table-column field="stat_flag" sortable title="统计标记" width="100"></vxe-table-column>
                  <vxe-table-column field="other_flag" sortable title="其它标记" width="100"></vxe-table-column>
                  <vxe-table-column field="status" sortable title="状态" width="60"></vxe-table-column>
                  <vxe-table-column field="lab_add" sortable title="实验室新增" width="120"></vxe-table-column>
                  <vxe-table-column field="add_dt" sortable title="新增时间" width="100"></vxe-table-column>
                  <vxe-table-column field="add_user" sortable title="新增人" width="100"></vxe-table-column>
                  <vxe-table-column field="charge_flag" sortable title="计价标志" width="100"></vxe-table-column>
                  <vxe-table-column field="req_groupid" sortable title="分单类别" width="100"></vxe-table-column>
                  <vxe-table-column field="his_refcol1" sortable title="HIS表相关字段1" width="150"></vxe-table-column>
                  <vxe-table-column field="his_refcol2" sortable title="HIS表相关字段2" width="150"></vxe-table-column>
                  <vxe-table-column field="his_refcol3" sortable title="HIS表相关字段3" width="150"></vxe-table-column>
                  <vxe-table-column field="reportid" sortable title="报告ID" width="100"></vxe-table-column>
              </vxe-table>
          </div>
      </div>
      <el-dialog title="请选择批量标本送出范围" :visible.sync="dialogVisible" width="30%" v-el-drag-dialog :close-on-click-modal="false">
          <table style="width: 100%; border-spacing: 0px; margin-top: 5px; height: 100%">
              <tr>
                  <td>
                      <span>采样时间：</span>
                  </td>
                  <td>
                      <div style="font-size: 12px; font-weight: 800; margin-top: 5px">
                          <el-date-picker v-model="startdt" type="date" placeholder="采样时间" value-format="yyyy-MM-dd" style="width: 150px" @change="getmultoption()"></el-date-picker>
                          -
                          <el-date-picker v-model="enddt" type="date" placeholder="采样时间" value-format="yyyy-MM-dd" style="width: 150px" @change="getmultoption()"></el-date-picker>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td>
                      <span>采样窗口：</span>
                  </td>
                  <td>
                      <div style="font-size: 12px; font-weight: 800; margin-top: 5px">
                          <el-select v-model="collectwindowid" @dblclick.native="popMultipleChk(collectwindowid, 'collectwindowid', collectwindowidOption, '采样窗口选择')" placeholder="双击选择窗口" filterable clearable style="width: 80%">
                              <el-option v-for="(item, index) in collectwindowidOption" :value="item.data" :label="item.display" :key="index"></el-option>
                          </el-select>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td>
                      <span>采样人工作组：</span>
                  </td>
                  <td>
                      <div style="font-weight: 800; margin-top: 5px">
                          <rm-ddl-common :appendtobody="true" datatype="labgroup" :clearable="true" dataname="检验工作组" v-model="labgroupid" width="80%" @change="labgroupChange" :disabled="isdisabled"></rm-ddl-common>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td>
                      <span>采样人：</span>
                  </td>
                  <td>
                      <div v-if="this.isonlypersonalsampledata == '0'" style="font-size: 12px; font-weight: 800; margin-top: 5px">
                          <el-select v-model="sampleduser" @dblclick.native="popMultipleChk(sampleduser, 'sampleduser', sampleduserOption, '采样人选择')" placeholder="双击选择采样人" filterable clearable style="width: 80%">
                              <el-option v-for="(item, index) in sampleduserOption" :value="item.data" :label="item.display" :key="index"></el-option>
                          </el-select>
                      </div>
                      <div v-else style="font-size: 12px; font-weight: 800; margin-top: 5px">
                          <el-select v-model="sampleduser" @dblclick.native="popMultipleChk(sampleduser, 'sampleduser', sampleduserOption, '采样人选择')" placeholder="双击选择采样人" filterable style="width: 80%">
                              <el-option v-for="(item, index) in sampleduserOption" :value="item.data" :label="item.display" :key="index"></el-option>
                          </el-select>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td>
                      <span>标本类型：</span>
                  </td>
                  <td>
                      <div style="font-size: 12px; font-weight: 800; margin-top: 5px">
                          <el-select v-model="specimenval" placeholder="" style="width:80%" @dblclick.native="popMultipleChk(specimenval,'specimenval',specimenOption,'标本类型选择')" filterable clearable>
                              <el-option v-for="(item,index) in specimenOption" :key="index" :value="item.data" :label="item.display"></el-option>
                          </el-select>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td>
                      <span>申请项目：</span>
                  </td>
                  <td>
                      <div style="font-size: 12px; font-weight: 800; margin-top: 5px">
                          <el-select v-model="reqitemval" placeholder="" style="width:80%" @dblclick.native="popMultipleChk(reqitemval,'reqitemval',reqitemOption,'申请项目选择')" filterable clearable>
                              <el-option v-for="(item,index) in reqitemOption" :key="index" :value="item.data" :label="item.display"></el-option>
                          </el-select>
                      </div>
                  </td>
              </tr>
          </table>
          <div align="right" style="width: 100%; margin-top: 10px">
              <el-button @click="GetMultBrcode()" icon="el-icon-document">确认</el-button>
              <el-button @click="dialogVisible = false" icon="el-icon-close">取消</el-button>
          </div>
      </el-dialog>

      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="dlgTitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
          <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
      </el-dialog>
      <el-dialog width="850px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="包条码送出历史清单" :visible.sync="dialogHistoryTableVisible">
          <template>
              <div style="height: 480px; width: 100%; position: relative">
                  <div style="height: 40px; width: 100%">
                      <table style="font-size: 12px; white-space: nowrap; max-width: 1170px">
                          <tr>
                              <td>创建时间</td>
                              <td>
                                  <el-date-picker v-model="startdt" :able="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%; min-width: 100px" :picker-options="pickerOptions" :clearable="false" :key="startkey"> </el-date-picker>
                              </td>
                              <td align="center">至</td>
                              <td>
                                  <el-date-picker v-model="enddt" type="date" :able="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%; min-width: 100px" :picker-options="pickerOptions" :clearable="false" :key="endkey"> </el-date-picker>
                              </td>
                              <td>创建人</td>
                              <td>
                                  <rm-ddl-common datatype="userinfo" dataname="用户" v-model="create_user" width="150px"></rm-ddl-common>
                              </td>
                              <td>
                                  <el-button @click="btnHistoryQuery()" icon="el-icon-search">查询</el-button>
                                  <el-button @click="btnHistoryPrint()" icon="el-icon-printer">打印包条码</el-button>
                              </td>
                          </tr>
                      </table>
                  </div>
                  <div style="height: 400px; top: 60px; width: 100%">
                      <vxe-table :data.sync="historytableData" :loading="historyloading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row class="mytablestyle" highlight-hover-column ref="hTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                          <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                          <vxe-table-column align="center" type="index" title="序号" width="40"></vxe-table-column>
                          <vxe-table-column field="packagebarcode" sortable title="传送条码" width="100"></vxe-table-column>
                          <vxe-table-column field="samplecount" sortable title="标本数量" width="65"></vxe-table-column>
                          <vxe-table-column field="createusername" sortable title="创建人" width="60"></vxe-table-column>
                          <vxe-table-column field="createtime" sortable title="创建时间" width="120"></vxe-table-column>
                          <vxe-table-column field="sendusername" sortable title="送出人" width="60"></vxe-table-column>
                          <vxe-table-column field="senddeptname" sortable title="送出部门" width="80"></vxe-table-column>
                          <vxe-table-column field="recievedeptname" sortable title="接收部门" width="80"></vxe-table-column>
                          <vxe-table-column field="transtime" sortable title="交接时间" width="120"></vxe-table-column>
                          <vxe-table-column field="statusname" sortable title="状态" width="60"></vxe-table-column>
                      </vxe-table>
                  </div>
              </div> </template
      ></el-dialog>
  </div>
</template>


<script>
import { Promise } from "q";
import { invalid } from "moment";
import XE from "xe-utils"; //引入工具类
export default {
  name: "REQ120",
  data() {
      return {
          dialogVisible: false,
          buttonwidth: "",
          pagetop: {
              height: "105px", //70/37
          },
          pagecenter: {
              top: "110px", //75/42
          },
          middle_center: {
              position: "absolute",
              top: "0px",
              bottom: "0px",
              right: "305px",
              left: "305px",
          },
          recieve_dept: "",
          is4402: true,
          is4401: true,
          startkey: 0,
          endkey: 0,
          drawagain: 0, //监控 数据变化 再次渲染
          barcode: "",
          master_data: [],
          master_data_show: [],
          detail_data: [],
          detail_loading: false,
          packagebarcode: "",
          trans_data: [],
          dialogMultipleVisible: false,
          collectwindowid: [],
          sampleduser: [],
          collectwindowidOption: [],
          sampleduserOption: [],
          option1: [],
          option2: [],
          fieldname: "",
          dlgTitle: "",
          startdt: this.$pub.InitDateTime2(0).datefrom,
          enddt: this.$pub.InitDateTime2(0).dateto,
          send_dept: "",
          send_user: "",
          last_sendno: 0,
          auto_dept: true,
          ck_auto_dept: true,
          ck_noview_print: true,
          ck_print_paging: true,
          ReqItemstyle: "5035",
          total: 0,
          maintotal: 0,
          rdysendtotal: 0,
          packagestyleid: "",
          hidpackagebarcode: "", // 自动识别科室 未选中时 使用
          specimen_number: 0, // 标本数量
          historytableData: [], // 包条码送出历史
          dialogHistoryTableVisible: false, // 历史记录弹出
          historyloading: false,
          create_user: this.$tool.getSession(this.$tool.loginuserno),
          isadd: "", // 是否新增
          pickerOptions: {
              shortcuts: [
                  {
                      text: "今天",
                      onClick(picker) {
                          picker.$emit("pick", new Date());
                          _that.sample_startdt = new Date();
                          _that.sample_enddt = new Date();
                      },
                  },
              ],
          },
          cx_isprintpackagebarcode: "",
          //运送人
          senduserinfoval: "",
          //标本送出必须录入运送人
          sendusermustinput: "",
          //运送人必须登录
          sendusermustlogin: "",
          // 批量获取待送出标本时,只获取本人采样确认数据
          isonlypersonalsampledata: "",
          //  门诊标本送出时进行采样确认
          sendsampleconfirm:"",
          selectOption: "",
          isdisabled: false,
          labgroupid: "",
          mixbarcodecnt: 0,
          combarcodecnt: 0,
          mixpeoplecnt: 0,
          callwindowid:0,
          loginutype:"",
          samplingPos:"",
          dontusedefaultreqvalue: "",
          reqoutneedlogin: "",
          afterreqoutclear: "",
          issendoutsuccess: "0",
          reqoutclearwithcarrier: "",
          reqitemval: "",//批量获取-申请项目
          reqitemOption: [],
          specimenval: "",//批量获取-标本类型
          specimenOption: [],
      };
  },
  created() {
      this.get_secoption();
      //this.getmultoption();
  },
  mounted() {},
  updated() {},
  computed: {
      newname() {
          return this.pagetop.height;
      },
  },
  watch: {
      newname(newval) {
          this.drawagain = this.drawagain + 1;
      },
  },
  methods: {
      /*
      action: "get_secoption"
      res[0]       4401 条码送出时,生成移交记录  true:"1" false:"0"
      res[1]       4402 条码送出时,须选目标科室  true:"1" false:"0"
      res[2]       默认送出人
      res[3]       默认执行科室
      res[4]       包条码样式id
      res[5]       获取标本送出时是否打印包条码
      res[6]       标本送出必须录入运送人
      res[7]       运送人必须登录
      res[8]       批量获取待送出标本时,只获取本人采样确认数据
      res[9]       门诊标本送出时进行采样确认
       */
      get_secoption() {
          this.loginutype = this.$tool.getSession(this.$tool.loginutype);
          //获取设置
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_secoption",
                  },
              })
              .then((res) => {
                  this.$nextTick(() => {
                      if (res[0] == "0") {
                          //不生成移交记录
                          this.is4401 = false;
                          this.ck_auto_dept = false;
                          this.middle_center.left = "0px";
                          this.pagecenter.top = "42px";
                          this.pagetop.height = "37px";
                      }
                      if (res[0] == "1") {
                          //生成移交记录 只需看4402
                          this.ck_auto_dept = true;
                          this.middle_center.left = "305px";
                      }
                      if (res[1] == "0" && res[0] == "0") {
                          this.is4402 = false; //√
                      }
                      if (res[1] == "1") {
                      }
                      this.send_user = res[2];
                      this.send_dept = res[3];
                      this.packagestyleid = res[4];
                      this.cx_isprintpackagebarcode = res[5];
                      this.sendusermustinput = res[6];
                      this.sendusermustlogin = res[7];
                      this.isonlypersonalsampledata = res[8];
                      this.sendsampleconfirm = res[9];
                      this.dontusedefaultreqvalue= res[10];
                      this.reqoutneedlogin= res[11];
                      this.afterreqoutclear= res[12];
                      this.reqoutclearwithcarrier= res[13];
                      if (this.isonlypersonalsampledata == "1") {
                          this.isdisabled = true;
                      }
                  });
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      getmultoption() {
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_multoption",
                      startdt: this.startdt,
                      enddt: this.enddt,
                      labgroupid:this.labgroupid,
                  },
              })
              .then((res) => {
                  this.collectwindowidOption = res.collectwindowidOption;
                  if(res.collectwindowidOption != null && res.collectwindowidOption.length >0 &&  res.callwindowid != "0"){
                      this.collectwindowid = res.callwindowid;
                  }
                  this.sampleduserOption = res.sampleduserOption;
                  let currentuser = this.$tool.getSession(this.$tool.loginuserno);
                  if (this.sampleduserOption.length > 0) {
                      if(!!this.sampleduser){
                          currentuser = this.sampleduser;
                      }
                      if(this.dontusedefaultreqvalue != '1'){
                          for (let index = 0; index < this.sampleduserOption.length; index++) {
                              const element = this.sampleduserOption[index];
                              if (element.data == currentuser) {
                                  this.sampleduser = element.data;
                                  break;
                              }
                          }
                          if (this.sampleduser == "") {
                              this.sampleduser = this.sampleduserOption[0].data;
                          }
                      }
                  }
                  else{
                      this.sampleduser = "";
                  }
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },

      labgroupChange(code, name) {
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_multoption",
                      startdt: this.startdt,
                      enddt: this.enddt,
                      labgroupid: code,
                  },
              })
              .then((res) => {
                  localStorage.setItem("req120labgroup", code);
                  this.sampleduser = "";
                  this.sampleduserOption = res.sampleduserOption;
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      showbatchwindow() {
          // 每次点击“批量获取标本”时，重新获取采样人集合
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_multoption",
                      startdt: this.startdt,
                      enddt: this.enddt,
                      labgroupid: this.labgroupid,
                      isbtn: '1',
                  },
              })
              .then((res) => {
                  this.reqitemOption = res.reqitemOption;
                  this.specimenOption = res.specimenOption;

                  this.collectwindowidOption = res.collectwindowidOption;
                  if(res.collectwindowidOption != null && res.collectwindowidOption.length >0 &&  res.callwindowid != "0"){
                      this.collectwindowid = res.callwindowid;
                  }
                  this.sampleduserOption = res.sampleduserOption;
                  this.dialogVisible = true;
                  this.labgroupid = localStorage.getItem("req120labgroup");
                  let currentuser = this.$tool.getSession(this.$tool.loginuserno);
                  if (this.sampleduserOption.length > 0) {
                      if(!!this.sampleduser){
                          currentuser = this.sampleduser;
                      }
                      if(this.dontusedefaultreqvalue != '1'){
                          for (let index = 0; index < this.sampleduserOption.length; index++) {
                              const element = this.sampleduserOption[index];
                              if (element.data == currentuser) {
                                  this.sampleduser = element.data;
                                  break;
                              }
                          }
                          if (this.sampleduser == "") {
                              this.sampleduser = this.sampleduserOption[0].data;
                          }
                      }
                  }
                  else{
                      this.sampleduser = "";
                  }
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },

      // 批量获取标本 确定 按钮事件
      GetMultBrcode() {
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_multbarcode",
                      recieve_dept: this.recieve_dept,
                      is4402: this.is4402 ? "1" : "0", //true1:判断科室 false1:不判断科室
                      startdt: this.startdt,
                      enddt: this.enddt,
                      collectwindowid: this.collectwindowid,
                      sampleduser: this.sampleduser,
                      samgroupid: this.labgroupid,
                      reqitemval: this.reqitemval,
                      specimenval: this.specimenval,
                  },
              })
              .then((val) => {
                  val.data.forEach((res) => {
                      let reslast = res;
                      //过滤已存在的条码号
                      if (this.master_data.filter((x) => x.barcode == res.Item1.barcode).length > 0) {
                      } else {
                          //接收到条码 显示该条数据到界面
                          res.Item1.recievedeptno = res.Item2;
                          res.Item1.recievedeptname = res.Item3;
                          this.master_data.unshift(res.Item1);

                          XE.clear(this.master_data_show);
                          this.master_data_show = XE.clone(this.master_data, true);
                          this.maintotal++;
                          this.specimen_number++;
                          if (res.Item1.ismixbarcode == "1") {
                              this.mixbarcodecnt++;
                              this.mixpeoplecnt = parseInt(this.mixpeoplecnt) + parseInt(res.Item1.mixcnt);
                          } else {
                              this.combarcodecnt++;
                          }

                          if (this.is4401) {
                              //4401
                              let is_TransHaven = false;
                              XE.each(this.trans_data, (item, key) => {
                                  if (item.recievedeptno == res.Item2) {
                                      is_TransHaven = true;
                                      this.trans_data[key].samplecount = Number(this.trans_data[key].samplecount) + 1;
                                      this.trans_data[key].last_barcode = res.Item1.barcode;
                                      this.trans_data[key].last_user = res.Item1.pat_name;
                                  }
                              });
                              if (!is_TransHaven) {
                                  //添加Trans记录
                                  let tranInfo = {
                                      packagebarcode: "",
                                      recievedeptno: reslast.Item2,
                                      recievedeptname: reslast.Item3,
                                      samplecount: 1,
                                      last_barcode: reslast.Item1.barcode,
                                      last_user: reslast.Item1.pat_name,
                                  };
                                  this.trans_data.push(tranInfo);
                              }
                          }
                          this.HightlightPos(); //全选该条码
                      }
                  });

                  XE.each(this.trans_data, (item, key) => {
                      this.$refs.trans_table.setSelection(this.trans_data[key], true);
                      this.querytransdetail(this.trans_data[key]);
                  });
                  this.$refs.trans_table.setCurrentRow(this.trans_data[0]);
                  this.querytransdetail(this.trans_data[0]);
                  this.total = this.master_data_show.length;
                  if(this.sendsampleconfirm == "1"){
                      this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0||item.req_stat == 1||item.req_stat == 8 || item.req_stat == 2).length;
                  }
                  else{
                      this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
                  }
                  this.dialogVisible = false;
              })
              .catch((e) => {
                  this.dialogVisible = false;
                  this.HightlightPos(); //全选该条码
                  this.$message.error(e);
              });
      },

      //采样窗口选择 弹窗时间
      popMultipleChk(e, fieldname, option, title) {
          let temp = XE.clone(option, true);
          this.option1 = [];
          this.option2 = [];
          if (e != "") {
              let k = e.split(",");
              k.forEach((item) => {
                  let ndata = temp.find((m) => m.data == item);
                  if (ndata != undefined && ndata != null) {
                      this.option2.push(ndata);
                  }
              });
              temp.forEach((item) => {
                  if (k.indexOf(item.data + "") < 0) {
                      this.option1.push(item);
                  }
              });
          } else {
              this.option1 = temp;
          }
          this.fieldname = fieldname;
          this.dlgTitle = title;
          this.dialogMultipleVisible = true;
      },
      closedialog(value, name) {
          if (value != "close") {
              this[name] = value;
          }
          this.dialogMultipleVisible = false;
      },
      //全选条码框
      HightlightPos(myField) {
          if (!myField) myField = document.getElementById("barcodediv");
          myField.selectionStart = 0;
          myField.selectionEnd = myField.value.length;
      },
      //聚焦条码框
      FocusBarcode(myField) {
          if (!myField) myField = document.getElementById("barcodediv");
          myField.focus();
          myField.select();
      },
      autoFocusBarcode(){
          setTimeout(() => {
              this.FocusBarcode(); //聚焦到条码框
          }, 100);
      },
      // 条码号 回车事件
      ScanBarcode(e) {
          let ishaven = false;
          XE.each(this.master_data, (item, key) => {
              if (item.barcode == XE.trim(this.barcode)) {
                  this.$message({
                      message: "已经扫过该条码！",
                      type: "warning",
                  });
                  this.barcode = this.barcode + " " + "已经扫过该条码！";
                  ishaven = true;
              }
          });
          if (ishaven) {
              setTimeout(() => {
                  this.HightlightPos(); //全选该条码
              }, 15);
              return false;
          }
          if (this.barcode == "") {
              return false;
          }
          if (this.recieve_dept == "" && this.is4402 && !this.is4401) {
              this.$message({
                  message: "请选择目标科室！",
                  type: "warning",
              });
              this.barcode = this.barcode + " " + "请选择目标科室！";
              setTimeout(() => {
                  this.HightlightPos(); //全选该条码
              }, 15);
              return false;
          }
          // 如果 自动识别科室选中
          if (!this.ck_auto_dept && this.hidpackagebarcode != "" && this.hidpackagebarcode != null && this.isadd == "") {
              this.$confirm("界面已有送出打包样本，是否沿用相同包条码?", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              })
                  .then(() => {
                      this.isadd = "1";
                  })
                  .catch(() => {
                      this.isadd = "2";
                      this.hidpackagebarcode = "";
                      this.master_data = [];
                      this.master_data_show = [];
                      this.detail_data = [];
                      this.maintotal = 0;
                      this.specimen_number = 0;
                      this.total = 0;
                      this.rdysendtotal = 0;
                      this.ScanBarcode();
                  });
          }

          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_dept",
                      barcode: this.barcode,
                      recieve_dept: this.recieve_dept,
                      is4402: this.is4402 ? "1" : "0", //true1:判断科室 false1:不判断科室
                  },
              })
              .then((res) => {
                  let reslast = res;
                  if (res.Item1 != "1") {
                      this.HightlightPos(); //全选该条码
                      this.$message.error(res.Item2);
                  } else {
                      //接收到条码 显示该条数据到界面
                      res.Item3.recievedept = reslast.Item4.trim();
                      res.Item3.recievedeptname = reslast.Item5;
                      this.master_data.splice(0, 0, res.Item3);

                      XE.clear(this.master_data_show);
                      this.master_data_show = XE.clone(this.master_data, true);

                      this.maintotal++;
                      this.specimen_number++;
                      if (res.Item3.ismixbarcode == "1") {
                          this.mixbarcodecnt++;
                          this.mixpeoplecnt = parseInt(this.mixpeoplecnt) + parseInt(res.Item3.mixcnt);
                      } else {
                          this.combarcodecnt++;
                      }
                      if (this.ck_auto_dept) {
                          if (this.is4401) {
                              let is_TransHaven = false;
                              XE.each(this.trans_data, (item, key) => {
                                  if (item.recievedeptno == res.Item4.trim()) {
                                      is_TransHaven = true;
                                      this.trans_data[key].samplecount = Number(this.trans_data[key].samplecount) + 1;
                                      this.trans_data[key].last_barcode = res.Item3.barcode;
                                      this.trans_data[key].last_user = res.Item3.pat_name;
                                      this.$refs.trans_table.setCurrentRow(item);
                                      this.querytransdetail(item);
                                  }
                              });
                              if (!is_TransHaven) {
                                  //添加Trans记录
                                  let tranInfo = {
                                      packagebarcode: "",
                                      recievedeptno: reslast.Item4.trim(),
                                      recievedeptname: reslast.Item5,
                                      samplecount: 1,
                                      last_barcode: reslast.Item3.barcode,
                                      last_user: reslast.Item3.pat_name,
                                  };
                                  this.trans_data.push(tranInfo);
                                  this.$refs.trans_table.setCurrentRow(tranInfo);
                                  this.querytransdetail(tranInfo);
                                  this.total = this.master_data_show.length;
                                  //this.rdysendtotal = this.master_data_show.filter((x) => x.req_stat == "2").length;
                                  if(this.sendsampleconfirm == "1"){
                                      this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8 || item.req_stat == 2).length;
                                  }
                                  else{
                                      this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
                                  }
                              }
                          }
                          this.HightlightPos(); //全选该条码

                          XE.each(this.trans_data, (item, key) => {
                              this.$refs.trans_table.setSelection(this.trans_data[key], true);
                              // this.querytransdetail(this.trans_data[key]);
                              // this.total = this.master_data_show.length;
                              // this.rdysendtotal = this.master_data_show.filter((x) => x.req_stat == "2").length;
                          });
                      } else {
                          this.total = this.master_data_show.length;
                          //this.rdysendtotal = this.master_data_show.filter((x) => x.req_stat == "2").length;
                          if(this.sendsampleconfirm == "1"){
                              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8 || item.req_stat == 2).length;
                          }
                          else{
                              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
                          }
                          this.$refs.master_table.setCurrentRow(this.master_data_show[0]);
                          this.querydetail(this.master_data_show[0]);
                      }
                  }
              })
              .catch((e) => {
                  this.HightlightPos(); //全选该条码
                  this.$message.error(e);
              });
      },

      // 主记录 行改变事件
      master_table_changeEvent({ row, rowIndex }) {
          this.querydetail(row);
      },
      querydetail(row) {
          if (row) {
              this.detail_loading = true;
              this.$tool
                  .request({
                      url: "REQ/REQ1/REQ120",
                      method: "post",
                      data: {
                          action: "get_datail",
                          barcode: row.barcode,
                      },
                  })
                  .then((res) => {
                      this.detail_data = res;
                      this.detail_loading = false;
                  })
                  .catch((e) => {
                      this.$message.error(e);
                  });
          }
      },
      //删除
      btnDelete() {
          try {
              var delrow = this.$refs.master_table.getCurrentRow();
              if (delrow) {
                  var alld = this.master_data_show;
                  var rowindex = alld.indexOf(delrow);
                  this.master_data_show.splice(rowindex, 1);
                  let havedata = this.master_data_show;

                  var master_alld = this.master_data;
                  var master_rowindex = master_alld.indexOf(delrow);
                  this.master_data.splice(master_rowindex, 1);

                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.master_table.setCurrentRow(selectrow);
                      this.querydetail(selectrow);
                  } else {
                      //清空右边
                      this.detail_data = [];
                  }
                  //重新计算左边表格数据
                  this.dataClassReload(havedata);
              }
              this.autoFocusBarcode();
          } catch (e) {
              console.log("error", e);
              this.autoFocusBarcode();
          }
      },
      dataClassReload(havedata) {
          var sel_transrow = this.$refs.trans_table.getCurrentRow();
          var curr_length = this.trans_data.length;
          if(havedata.length > 0){
              //当前分类下存在数据，则数量减一
              sel_transrow.samplecount = Number(sel_transrow.samplecount) - 1;
              sel_transrow.last_barcode = havedata[0].barcode;
              sel_transrow.last_user = havedata[0].pat_name;
          } else {
              //无数据，删除当前分类
              var trans_alld = this.trans_data;
              var trans_rowindex = trans_alld.indexOf(sel_transrow);
              this.trans_data.splice(trans_rowindex, 1);
          }

          this.total = this.master_data_show.length;
          this.maintotal = this.master_data.length;
          if(this.sendsampleconfirm == "1"){
              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0||item.req_stat == 1||item.req_stat == 8 || item.req_stat == 2).length;
          }
          else{
              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
          }

          if(this.trans_data.length > 0 && curr_length > this.trans_data.length){
              this.$refs.trans_table.setCurrentRow(this.trans_data[0]);
              this.querytransdetail(this.trans_data[0]);
          }
      },
      // 送出事件
      true4401_sendEvent() {
          if(this.reqoutneedlogin == '1'){
              //获取本地缓存
              var logininfo = this.$tool.getSession("req120logininfo");
              if (logininfo != null && logininfo != "") {
                  let jsondate = JSON.parse(logininfo);
                  //修改送出人为缓存所记录的
                  this.send_user = jsondate.userid;
                  //执行送出
                  this.true_sendEvent();
              }
              else{
                  //需要登录
                  this.$rm_Login({
                      type: "用户登录验证",
                      btn: {
                          confirmBtnText: "确定",
                          cancelBtnText: "取消",
                      },
                  })
                      .then((res) => {
                          if (res.flag == "1") {
                              //写入缓存
                              let jsondate = {
                                  userid: res.userid,
                                  username: res.username,
                              };
                              let modListJson = JSON.stringify(jsondate);
                              this.$tool.setSession("req120logininfo", modListJson);
                              //修改当前送出人
                              this.send_user = res.userid;
                              //执行送出
                              this.true_sendEvent();
                          } else {
                              //登录失败
                              this.$message.warning("登陆失败，请检查输入的用户名密码！");
                          }
                      })
                      .catch((e) => {
                          this.$message.warning(e);
                          console.log(e);
                      });
              }
          }
          else{
              this.true_sendEvent();
          }
      },
      //送出
      true_sendEvent(){
          let isauto = this.ck_auto_dept ? "1" : "0";
          this.samplingPos = "";
          if (this.ck_auto_dept) {
              //  自动识别接收科室  选中
              this.trans_sendEvent();
          } else {
              let masterlist = [];
              XE.each(this.$refs.master_table.data, (item, key) => {
                  if ( this.sendsampleconfirm == "1" && ( item.req_stat == "0" || item.req_stat == "1" ||item.req_stat =="8" || item.req_stat == "2") ) {
                      masterlist.push(this.$refs.master_table.data[key]);
                  }
                  else if(this.sendsampleconfirm != "1" &&  item.req_stat == "2"){
                      masterlist.push(this.$refs.master_table.data[key]);
                  }
              });

              if(masterlist.length == 0){
                  this.$message.warning("没有可送出的数据");
                  this.autoFocusBarcode();
                  return false;
              }

              let hidpackagebarcode = this.hidpackagebarcode;
              let transinfo = [];
              let tran = { packagebarcode: hidpackagebarcode, recievedeptno: "", samplecount: masterlist.length };
              transinfo.push(tran);

              if (this.sendusermustinput == "1" && !this.senduserinfoval) {
                  this.$alert("请先选择运送人！", "提示", {
                      confirmButtonText: "确定",
                  });
                  return false;
              }
              //  自动识别接收科室  未选中
              if (this.recieve_dept == "") {
                  this.$confirm("目标科室为空，确定不选择目标科室?", "提示", {
                      confirmButtonText: "确定",
                      cancelButtonText: "取消",
                      type: "warning",
                  })
                      .then(() => {
                          this.$tool
                              .request({
                                  url: "REQ/REQ1/REQ120",
                                  method: "post",
                                  data: {
                                      action: "send_specimen",
                                      masterlist: masterlist,
                                      trans: transinfo,
                                      hidpackagebarcode: hidpackagebarcode,
                                      senddept: this.send_dept,
                                      recievedept: this.recieve_dept,
                                      senduser: this.send_user,
                                      senduser1: this.senduserinfoval,
                                      isauto: isauto,
                                  },
                              })
                              .then((res) => {
                                  if (res.Item1 == "1") {
                                      this.$message({
                                          message: "送出成功",
                                          type: "success",
                                      });
                                      this.hidpackagebarcode = res.Item4.trim();
                                      this.master_data.forEach((item) => {
                                          var returnlist = res.Item3;
                                          for (let i = 0; i < returnlist.length; i++) {
                                              const ritem = returnlist[i];
                                              if (item.barcode == ritem.barcode) {
                                                  item.send_dt = ritem.send_dt;
                                                  item.send_username = ritem.send_username;
                                                  item.req_stat = ritem.req_stat;
                                                  item.packagebarcode = res.Item4.trim();
                                              }
                                          }
                                      });
                                      this.master_data_show = XE.clone(this.master_data, true);
                                     // this.rdysendtotal = this.master_data.filter((item) => item.req_stat == "2").length;
                                      if(this.sendsampleconfirm == "1"){
                                          this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8 || item.req_stat == 2).length;
                                      }
                                      else{
                                          this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 2).length;
                                      }
                                      var sampPosList = res.Item6;
                                      for (let i = 0; i < sampPosList.length; i++) {
                                          var sitem = sampPosList[i];
                                          if (this.samplingPos.indexOf(sitem) < 0) {
                                              this.samplingPos += sitem;
                                          }
                                      }
                                      // 提示打印包条码
                                      if (this.cx_isprintpackagebarcode == "1") {
                                          this.$rmConfirm({
                                              type: "提示",
                                              msg: "送出成功， 是否打印包条码？",
                                              btn: {
                                                  confirmBtnText: "确 定",
                                                  cancelBtnText: "取 消",
                                              },
                                          })
                                              .then(() => {
                                                  this.auto_dept_nocheck_pageCodePrint();
                                              })
                                              .catch(() => {
                                                  this.$message({
                                                      type: "info",
                                                      message: "已取消打印",
                                                  });
                                                  this.autoFocusBarcode();
                                              });
                                      } else if (this.cx_isprintpackagebarcode == "2") {
                                          this.auto_dept_nocheck_pageCodePrint();
                                      }
                                  } else if (res.Item1 == "0") {
                                      this.$message({
                                          message: res.Item2,
                                          type: "warning",
                                      });
                                  } else {
                                      this.$message.error(res.Item2);
                                  }
                                  this.autoFocusBarcode();
                              })
                              .catch((e) => {
                                  this.$message.error(e);
                                  this.autoFocusBarcode();
                              });
                      })
                      .catch(() => {
                          this.$message({
                              type: "info",
                              message: "已取消送出",
                          });
                      });
              } else {
                  this.send_sample_nocheck_dept();
              }
              this.isadd = "";
          }
          this.autoFocusBarcode();
      },
      //  打包送出 逻辑
      trans_sendEvent() {
          let translist = this.$refs.trans_table.getSelectRecords();
          if (translist.length > 0) {
              for (let i = 0; i < translist.length; i++) {
                  const transitem = translist[i];
                  let masterlist = [];
                  let havesendlist = [];
                  XE.each(this.master_data, (item, key) => {
                      if (item.recievedeptno == transitem.recievedeptno) {
                          if(this.sendsampleconfirm !="1"){
                              if ( item.req_stat == "2") {
                                  masterlist.push(this.master_data[key]);
                              } else {
                                  havesendlist.push(this.master_data[key]);
                              }
                          }
                          else{
                              if ( item.req_stat == "0"||item.req_stat == "1"||item.req_stat == "8" ||item.req_stat == "2" ) {
                                  masterlist.push(this.master_data[key]);
                              } else {
                                  havesendlist.push(this.master_data[key]);
                              }
                          }
                      }
                  });
                  if(masterlist.length == 0) continue;
                  let transinfo = [];
                  let tran = { packagebarcode: transitem.packagebarcode, recievedeptno: transitem.recievedeptno, samplecount: transitem.samplecount };
                  transinfo.push(tran);
                  let isauto = this.ck_auto_dept ? "1" : "0"; // 自动识别科室 是否选中
                  if (this.sendusermustinput == "1" && !this.senduserinfoval) {
                      this.$alert("请先选择运送人！", "提示", {
                          confirmButtonText: "确定",
                      });
                      return false;
                  }
                  this.$tool
                      .request({
                          url: "REQ/REQ1/REQ120",
                          method: "post",
                          data: {
                              action: "send_specimen",
                              masterlist: masterlist,
                              trans: transinfo,
                              senddept: this.send_dept,
                              recievedept: this.recieve_dept,
                              senduser: this.send_user,
                              senduser1: this.senduserinfoval,
                              hidpackagebarcode: "",
                              isauto: isauto,
                          },
                      })
                      .then((res) => {
                          if (res.Item1 == "1") {
                              this.last_sendno = res.Item5;
                              transitem.packagebarcode = res.Item4.trim();

                              this.master_data.forEach((item) => {
                                  var returnlist = res.Item3;
                                  for (let i = 0; i < returnlist.length; i++) {
                                      const ritem = returnlist[i];
                                      if (item.barcode == ritem.barcode) {
                                          item.send_dt = ritem.send_dt;
                                          item.send_username = ritem.send_username;
                                          item.req_stat = ritem.req_stat;
                                          item.packagebarcode = res.Item4.trim();
                                      }
                                  }
                              });
                              this.master_data_show = XE.clone(this.master_data, true);
                              this.total = this.master_data.length;
                             // this.rdysendtotal = this.master_data.filter((item) => item.req_stat == "2").length;
                              if(this.sendsampleconfirm == "1"){
                                  this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 0 || item.req_stat == 1 ||item.req_stat == 8 ||item.req_stat == 2).length;
                              }
                              else{
                                  this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 2).length;
                              }
                              var sampPosList = res.Item6;
                              for (let i = 0; i < sampPosList.length; i++) {
                                  var sitem = sampPosList[i];
                                  if (this.samplingPos.indexOf(sitem) < 0) {
                                      this.samplingPos += sitem;
                                  }
                              }
                              // this.$message({
                              //     message: "送出成功",
                              //     type: "success",
                              // });
                              // 提示打印包条码
                              this.issendoutsuccess = '1';//为了区分是送出成功后的打印
                              //送出成功后清除运送人
                              if(this.reqoutclearwithcarrier == '1'){
                                  this.senduserinfoval = '';
                              }
                              if (this.cx_isprintpackagebarcode == "1") {
                                  this.$rmConfirm({
                                      type: "提示",
                                      msg: "送出成功， 是否打印包条码？",
                                      btn: {
                                          confirmBtnText: "确 定",
                                          cancelBtnText: "取 消",
                                      },
                                  })
                                      .then(() => {
                                          this.BtnPageCodePrint();
                                      })
                                      .catch(() => {
                                          this.$message({
                                              type: "info",
                                              message: "已取消打印",
                                          });
                                          if(this.afterreqoutclear == '1'){
                                              //清除当前送出的数据
                                              this.BtnClear();
                                          }
                                          else{
                                              this.autoFocusBarcode();
                                          }
                                      });
                              } else if (this.cx_isprintpackagebarcode == "2") {
                                  this.BtnPageCodePrint();
                              }
                              else {
                                  if(this.afterreqoutclear == '1'){
                                      //清除当前送出的数据
                                      this.BtnClear();
                                  }
                              }
                          } else if (res.Item1 == "0") {
                              this.$message({
                                  message: res.Item2,
                                  type: "warning",
                              });
                          } else {
                              this.$message.error(res.Item2);
                          }
                          this.autoFocusBarcode();
                      })
                      .catch((e) => {
                          this.$message.error(e);
                          this.autoFocusBarcode();
                      });
              }
          } else {
              this.$message({
                  message: "请选择要送出的记录！",
                  type: "warning",
              });
          }
          this.autoFocusBarcode();
      },

      //  自动识别接收科室 未选中 送出事件
      send_sample_nocheck_dept() {
          let isauto = this.ck_auto_dept ? "1" : "0";
          let masterlist = [];
          XE.each(this.$refs.master_table.data, (item, key) => {
              if ( this.sendsampleconfirm=="1" &&(item.req_stat == "0" ||item.req_stat == "1" ||item.req_stat == "8" || item.req_stat == "2") ) {
                  masterlist.push(this.$refs.master_table.data[key]);
              }
              else if( this.sendsampleconfirm !="1" &&  item.req_stat == "2"){
                  masterlist.push(this.$refs.master_table.data[key]);
              }
          });
          let hidpackagebarcode = this.hidpackagebarcode;
          let transinfo = [];
          let tran = { packagebarcode: hidpackagebarcode, recievedeptno: "", samplecount: masterlist.length };
          transinfo.push(tran);
          if (this.sendusermustinput == "1" && !this.senduserinfoval) {
              this.$alert("请先选择运送人！", "提示", {
                  confirmButtonText: "确定",
              });
              return false;
          }
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "send_specimen",
                      masterlist: masterlist,
                      trans: transinfo,
                      hidpackagebarcode: hidpackagebarcode,
                      senddept: this.send_dept,
                      recievedept: this.recieve_dept,
                      senduser: this.send_user,
                      senduser1: this.senduserinfoval,
                      isauto: isauto,
                  },
              })
              .then((res) => {
                  if (res.Item1 == "1") {
                      this.hidpackagebarcode = res.Item4.trim();
                      this.master_data.forEach((item) => {
                          var returnlist = res.Item3;
                          for (let i = 0; i < returnlist.length; i++) {
                              const ritem = returnlist[i];
                              if (item.barcode == ritem.barcode) {
                                  item.send_dt = ritem.send_dt;
                                  item.send_username = ritem.send_username;
                                  item.req_stat = ritem.req_stat;
                                  item.packagebarcode = res.Item4.trim();
                                  item.recievedeptno = ritem.recievedeptno;
                                  item.recievedeptname = ritem.recievedeptname;
                              }
                          }
                      });
                      this.master_data_show = XE.clone(this.master_data, true);
                      //this.rdysendtotal = this.master_data.filter((item) => item.req_stat == "2").length;
                      if(this.sendsampleconfirm == "1"){
                          this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8 || item.req_stat == 2).length;
                      }
                      else{
                          this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 2).length;
                      }
                      this.$message({
                          message: "送出成功",
                          type: "success",
                      });
                      // 提示打印包条码
                      if (this.cx_isprintpackagebarcode == "1") {
                          this.$rmConfirm({
                              type: "提示",
                              msg: "送出成功， 是否打印包条码？",
                              btn: {
                                  confirmBtnText: "确 定",
                                  cancelBtnText: "取 消",
                              },
                          })
                              .then(() => {
                                  this.auto_dept_nocheck_pageCodePrint();
                              })
                              .catch(() => {
                                  this.$message({
                                      type: "info",
                                      message: "已取消打印",
                                  });
                                  this.autoFocusBarcode();
                              });
                      } else if (this.cx_isprintpackagebarcode == "2") {
                          this.auto_dept_nocheck_pageCodePrint();
                      }
                  } else if (res.Item1 == "0") {
                      this.$message({
                          message: res.Item2,
                          type: "warning",
                      });
                  } else {
                      this.$message.error(res.Item2);
                  }
                  this.autoFocusBarcode();
              })
              .catch((e) => {
                  this.$message.error(e);
                  this.autoFocusBarcode();
              });
      },

      // 自动识别科室 改变事件
      auto_dept_changeEvent() {
          this.$nextTick(() => {
              this.auto_dept = this.ck_auto_dept;
              if (this.ck_auto_dept) {
                  this.middle_center.left = "305px";

                  if (this.master_data.length > 0 && this.hidpackagebarcode != "") {
                      // 提示是否重新拆包
                      this.$confirm("已有送出打包样本，是否【拆分】重新打包?", "提示", {
                          confirmButtonText: "确定",
                          cancelButtonText: "取消",
                          type: "warning",
                      })
                          .then(() => {
                              this.$tool
                                  .request({
                                      url: "REQ/REQ1/REQ120",
                                      method: "post",
                                      data: {
                                          action: "cancel_specimen",
                                          packagebarcode: this.hidpackagebarcode,
                                      },
                                  })
                                  .then((res) => {
                                      if (res.msg.Item1 == "1") {
                                          this.splitpagecode();
                                      }
                                  })
                                  .catch((e) => {
                                      this.$message.error(e);
                                  });
                          })
                          .catch(() => {
                              this.trans_data = [];
                              this.master_data = [];
                              this.master_data_show = [];
                              this.detail_data = [];
                              this.hidpackagebarcode = [];
                              this.maintotal = 0;
                              this.specimen_number = 0;
                              this.total = 0;
                              this.rdysendtotal = 0;
                          });
                  } else {
                      this.dataclassification();
                  }
              } else {
                  this.middle_center.left = "0px";
                  let tlist = [];
                  let translist = this.trans_data;
                  for (let index = 0; index < translist.length; index++) {
                      const element = translist[index];
                      if (element.packagebarcode != "" && element.packagebarcode != null) {
                          tlist.unshift(element);
                      }
                  }
                  if (tlist.length > 1) {
                      this.$confirm("已有送出打包样本，是否【合并】重新打包?", "提示", {
                          confirmButtonText: "确定",
                          cancelButtonText: "取消",
                          type: "warning",
                      })
                          .then(() => {
                              for (let i = 0; i < tlist.length; i++) {
                                  const tran = tlist[i];
                                  // 作废已发出包条码
                                  this.$tool
                                      .request({
                                          url: "REQ/REQ1/REQ120",
                                          method: "post",
                                          data: {
                                              action: "cancel_specimen",
                                              packagebarcode: tran.packagebarcode,
                                          },
                                      })
                                      .then((res) => {
                                          if (res.msg.Item1 == "1") {
                                              // this.splitpagecode();
                                          }
                                      })
                                      .catch((e) => {
                                          this.$message.error(e);
                                      });
                              }
                              let datalist = this.master_data;
                              datalist.forEach((element) => {
                                  element.packagebarcode = "";
                                  element.req_stat = "2";
                              });
                              this.master_data_show = XE.clone(this.master_data, true);
                              this.total = this.master_data_show.length;
                              //this.rdysendtotal = this.master_data.filter((x) => x.req_stat == "2").length;
                              if(this.sendsampleconfirm == "1"){
                                  this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
                              }
                              else{
                                  this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 2).length;
                              }
                          })
                          .catch(() => {
                              this.master_data_show = XE.clone(this.master_data, true);
                              this.total = this.master_data_show.length;
                              //this.rdysendtotal = this.master_data.filter((x) => x.req_stat == "2").length;
                              if(this.sendsampleconfirm == "1"){
                                  this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
                              }
                              else{
                                  this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 2).length;
                              }
                          });
                  } else {
                      if (tlist.length == 1) {
                          this.hidpackagebarcode = tlist[0].packagebarcode;
                      }
                      // 界面显示所有的
                      this.master_data_show = XE.clone(this.master_data, true);
                      this.total = this.master_data_show.length;
                      //this.rdysendtotal = this.master_data.filter((x) => x.req_stat == "2").length;
                      if(this.sendsampleconfirm == "1"){
                          this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
                      }
                      else{
                          this.rdysendtotal = this.master_data.filter((item) => item.req_stat == 2).length;
                      }
                  }
              }
          });
      },

      // 拆分包条码
      splitpagecode() {
          // 作废成功，将界面的数据重新分包
          let datalist = this.master_data_show;
          this.master_data = [];
          this.master_data_show = [];
          this.trans_data = [];
          this.detail_data = [];
          this.maintotal = 0;
          this.specimen_number = 0;

          for (let index = 0; index < datalist.length; index++) {
              const element = datalist[index];
              element.packagebarcode = "";
              element.req_stat = "2";
              // 重新分包
              this.master_data.unshift(element);

              XE.clear(this.master_data_show);
              this.master_data_show = XE.clone(this.master_data, true);

              this.maintotal++;
              this.specimen_number++;
              if (this.is4401) {
                  //4401
                  let is_TransHaven = false;
                  XE.each(this.trans_data, (item, key) => {
                      if (item.recievedeptno == element.recievedeptno.trim()) {
                          is_TransHaven = true;
                          this.trans_data[key].samplecount = Number(this.trans_data[key].samplecount) + 1;
                          this.trans_data[key].last_barcode = element.barcode;
                          this.trans_data[key].last_user = element.pat_name;
                          this.$refs.trans_table.setCurrentRow(element);
                      }
                  });
                  if (!is_TransHaven) {
                      //添加Trans记录
                      let tranInfo = {
                          packagebarcode: "",
                          recievedeptno: element.recievedeptno.trim(),
                          recievedeptname: element.recievedeptname,
                          samplecount: 1,
                          last_barcode: element.barcode,
                          last_user: element.pat_name,
                      };
                      this.trans_data.push(tranInfo);
                      this.$refs.trans_table.setCurrentRow(tranInfo);
                      this.querytransdetail(tranInfo);
                      this.total = this.master_data_show.length;
                     // this.rdysendtotal = this.master_data_show.filter((x) => x.req_stat == "2").length;
                      if(this.sendsampleconfirm == "1"){
                          this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
                      }
                      else{
                          this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
                      }
                  }
              }
              //this.HightlightPos(); //全选该条码

              XE.each(this.trans_data, (item, key) => {
                  this.$refs.trans_table.setSelection(this.trans_data[key], true);
                  this.querytransdetail(this.trans_data[key]);
                  this.total = this.master_data_show.length;
                  //this.rdysendtotal = this.master_data_show.filter((x) => x.req_stat == "2").length;
                  if(this.sendsampleconfirm == "1"){
                      this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
                  }
                  else{
                      this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
                  }
              });
          }
      },

      // 数据分类
      dataclassification() {
          this.trans_data = [];
          let maindata = this.master_data;

          maindata.forEach((res) => {
              if (this.is4401) {
                  //4401
                  let is_TransHaven = false;
                  let packagebarcode = res.packagebarcode;
                  XE.each(this.trans_data, (item, key) => {
                      if (item.recievedeptno == res.recievedeptno) {
                          is_TransHaven = true;
                          this.trans_data[key].samplecount = Number(this.trans_data[key].samplecount) + 1;
                          this.trans_data[key].last_barcode = res.barcode;
                          this.trans_data[key].last_user = res.pat_name;
                          this.trans_data[key].packagebarcode = packagebarcode;
                          this.trans_data[key].recievedeptno = res.recievedeptno;
                          this.trans_data[key].recievedeptname = res.recievedeptname;
                      }
                  });
                  if (!is_TransHaven) {
                      //添加Trans记录
                      let tranInfo = {
                          packagebarcode: packagebarcode,
                          recievedeptno: res.recievedeptno,
                          recievedeptname: res.recievedeptname,
                          samplecount: 1,
                          last_barcode: res.barcode,
                          last_user: res.pat_name,
                      };
                      this.trans_data.push(tranInfo);
                  }
              }
              this.HightlightPos(); //全选该条码
          });

          XE.each(this.trans_data, (item, key) => {
              this.$refs.trans_table.setSelection(this.trans_data[key], true);
              this.querytransdetail(this.trans_data[key]);
          });
          this.$refs.trans_table.setCurrentRow(this.trans_data[0]);
          this.querytransdetail(this.trans_data[0]);
          this.total = this.master_data_show.length;
          //this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
          if(this.sendsampleconfirm == "1"){
              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
          }
          else{
              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
          }
          this.dialogVisible = false;
      },

      checkMethod({ row }) {
          if (row.req_stat != "2" && row.send_user != "undefined" && row.send_user != "") {
              return false;
          } else {
              return true;
          }
      },
      // 包数据改变事件
      trans_table_changeEvent({ row, rowIndex, column, columnIndex }, event) {
          this.querytransdetail(row);
      },

      querytransdetail(row) {
          XE.clear(this.master_data_show);
          XE.each(this.master_data, (item, key) => {
              if (item.recievedeptno == row.recievedeptno) {
                  if (row.packagebarcode == "") {
                      if (item.packagebarcode == "") {
                          this.master_data_show.push(this.master_data[key]);
                      }
                  } else {
                      if (item.packagebarcode == "" || item.packagebarcode == row.packagebarcode) {
                          this.master_data_show.push(this.master_data[key]);
                      }
                  }

                  if (item.req_stat == "2") {
                      this.$refs.master_table.setSelection(this.master_data_show[0], true);
                  }
              }
          });
          this.total = this.master_data_show.length;
         // this.rdysendtotal = this.master_data_show.filter((x) => x.req_stat == "2").length;
          if(this.sendsampleconfirm == "1"){
              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 0 ||item.req_stat == 1 ||item.req_stat == 8|| item.req_stat == 2).length;
          }
          else{
              this.rdysendtotal = this.master_data_show.filter((item) => item.req_stat == 2).length;
          }

          this.$refs.master_table.setCurrentRow(this.master_data_show[0]);
          this.querydetail(this.master_data_show[0]);
      },

      trans_deleteEvent() {
          let row = this.$refs.trans_table.getRadioRow();
          if (!XE.isNull(row)) {
              XE.remove(this.trans_data, (item) => item.recievedeptno == row.recievedeptno);
              XE.remove(this.master_data, (item) => item.perform_dept == row.recievedeptno);
              XE.clear(this.master_data_show);
              this.master_data_show = XE.clone(this.master_data, true);
              XE.each(this.master_data_show, (item, key) => {
                  if (item.req_stat == "2") {
                      this.$refs.master_table.setSelection(this.master_data_show[key], true);
                  }
              });
          } else {
              this.$message({
                  message: "请选择要删除的记录！",
                  type: "warning",
              });
          }
      },

      //"rm-cancel"; //作废
      //"rm-disable"; //禁用
      //"rm-readonly"; //只读
      //"rm-alert"; //警告
      RowClassName_masterTable({ row, rowIndex }) {
          if(this.sendsampleconfirm == "1" &&  row.req_stat != "0" && row.req_stat != "1"&& row.req_stat != "8" && row.req_stat != "2"){
                  return "rm-readonly"; //禁用
          }
          else if(this.sendsampleconfirm != "1" && row.req_stat != "2"){
                  return "rm-readonly"; //禁用
          }
      },
      // 打印样式设计
      RptStyleSetting() {
          var str =" select req_groupna            as 分单类别,req_master_all.barcode as 条形码,pat_name               as 病人姓名,pat_sexname            as 性别,pat_agestr             as 年龄,specimen_name          as 标本类型,req_statname           as 状态,sample_items           as '申请项目(描述)',send_dt                as 送出时间,send_username          as 送出人,sampled_dt             as 采样时间,sampled_username       as 采样人,create_username        as 条码创建人,create_dt              as 创建时间,pat_typename           as 病人来源,pat_no                 as 病历号,base_amount            as 应收金额,req_deptname           as 申请科室,req_docname            as 申请医生,req_dt                 as 申请时间,print_dt               as '打印(执行)时间',print_username         as '打印(执行)人',prereport_dt           as 预出报告时间,prereport_comm         as 报告领取说明,pat_diag               as 临床诊断,pat_id                 as 病人ID,inp_date               as 入院日期,req_bedno              as 床号,pat_cardno             as 就诊卡号,pat_address            as 地址,pat_nation             as 国籍,pat_idcardno           as 身份证号,pat_phone              as 联系电话,charge_dt              as 计价时间,charge_username        as 计价人,amount                 as 实收金额,charge_typeno          as 费别代码,perform_dept           as 执行科室,original_reqno         as 原始单号,isnull(b.mixnum, 1)    as 明细数,d.samplecount          as 标本数量,c.packagebarcode       as 包条码号,e.deptname             as 接收部门,reclabgroupid          as 接收工作组,f.deptname             as 送出部门,'2'                    as 单采标本数,'3'                    as 混检标本数,comments               as 备注,u.username             as 创建者,'一号采样点' as 采样点 from req_master_all left join req_mixsample b on b.mixbarcode = req_master_all.barcode left join req_transdetail c on c.barcode = req_master_all.barcode left join Req_Trans d on d.packagebarcode = c.packagebarcode left join dc_dept e on e.deptname = d.recievedept left join dc_dept f on d.senddept = f.deptno left join secsysuser u on d.createuser = u.userno where req_master_all.barcode = (select top 1 req_master.barcode from req_master order by barcode desc) ";
          this.$pub.printlistbill(this, str, "3", this.ReqItemstyle, "门诊标本送出", "");
      },
      btnPrint_click() {
          // btype 打印类型 1：打印 2：打印条码
          var that = this;
          let alertmsg = "";
          // 打印
          var barcodeStr = "";
          var FullData = this.$refs.master_table.afterFullData;
          FullData.forEach(element => {
                      if (!!element.barcode) {
                          barcodeStr += "'" + element.barcode + "',";
                      }
                  });
          if(barcodeStr.endsWith(',')){
              barcodeStr = barcodeStr.substring(0, barcodeStr.length-1);
          }
          console.log(barcodeStr);
          var str =" select req_groupna            as 分单类别,req_master_all.barcode as 条形码,pat_name               as 病人姓名,pat_sexname            as 性别,pat_agestr             as 年龄,specimen_name          as 标本类型,req_statname           as 状态,sample_items           as '申请项目(描述)',send_dt                as 送出时间,send_username          as 送出人,sampled_dt             as 采样时间,sampled_username       as 采样人,create_username        as 条码创建人,create_dt              as 创建时间,pat_typename           as 病人来源,pat_no                 as 病历号,base_amount            as 应收金额,req_deptname           as 申请科室,req_docname            as 申请医生,req_dt                 as 申请时间,print_dt               as '打印(执行)时间',print_username         as '打印(执行)人',prereport_dt           as 预出报告时间,prereport_comm         as 报告领取说明,pat_diag               as 临床诊断,pat_id                 as 病人ID,inp_date               as 入院日期,req_bedno              as 床号,pat_cardno             as 就诊卡号,pat_address            as 地址,pat_nation             as 国籍,pat_idcardno           as 身份证号,pat_phone              as 联系电话,charge_dt              as 计价时间,charge_username        as 计价人,amount                 as 实收金额,charge_typeno          as 费别代码,perform_dept           as 执行科室,original_reqno         as 原始单号,isnull(b.mixnum, 1)    as 明细数,d.samplecount          as 标本数量,c.packagebarcode       as 包条码号,e.deptname             as 接收部门,reclabgroupid          as 接收工作组,f.deptname             as 送出部门,'" + this.combarcodecnt + "'                    as 单采标本数,'" + this.mixbarcodecnt + "'                    as 混检标本数,comments               as 备注,u.username             as 创建者,h.windowname                 as 采样点 from req_master_all left join req_mixsample b on b.mixbarcode = req_master_all.barcode left join req_transdetail c on c.barcode = req_master_all.barcode left join Req_Trans d on d.packagebarcode = c.packagebarcode left join dc_dept e on e.deptname = d.recievedept left join dc_dept f on d.senddept = f.deptno left join secsysuser u on d.createuser = u.userno left join req_collect g on req_master_all.collectbarcode = g.collectbarcode left join req_collectwindow h on req_master_all.collectwindowid = h.windowid and g.queuearea = h.queuearea where req_master_all.barcode in (" + barcodeStr + ") ";
          console.log(str);
          let sql = btoa(encodeURIComponent(str));
          jsObj.PrintCustomReport(this.ReqItemstyle, sql, this.$tool.getSession("loginuserno"), "门诊标本送出", "");
      },
      // 重打包条码
      BtnPageCodePrint() {
          let translist = this.$refs.trans_table.getSelectRecords();
          if (translist.length > 0) {
              let userno = this.$tool.getSession(this.$tool.loginuserno);
              for (let i = 0; i < translist.length; i++) {
                  const element = translist[i];
                  if (element.packagebarcode != null && element.packagebarcode != "") {
                      let sql = btoa(encodeURIComponent("select SampleCount as 标本数量, SendUser as 送出人, CONVERT(varchar,GETDATE(),120) as 打印时间,  PackageBarcode as 包条码号,  dc_dept.deptname as 接收部门,    RecLabGroupID as 接收工作组, bb.deptname as 送出部门,'" + this.combarcodecnt + "' as 单采标本数,'" + this.mixbarcodecnt + "' as 混检标本数,u.username as 创建者, comments as 备注,'" + this.samplingPos + "' as 采样点 from Req_Trans  left join dc_dept on Req_Trans.RecieveDept = dc_dept.deptno left join dc_dept bb  on Req_Trans.senddept = bb.deptno left join secsysuser u on Req_Trans.createuser = u.userno where Req_Trans.PackageBarcode = '" + element.packagebarcode.trim() + "'"));
                      jsObj.PrintCustomReport(this.packagestyleid, sql, userno, "打包条码样式", ""); // 正式打印模式
                      // jsObj.SetCustomPrintConfig(this.packagestyleid, sql, userno, "打包条码样式"); //设计模式
                  }
              }
          } else {
              this.$message({
                  message: "请选择要打印的包条码！",
                  type: "warning",
              });
          }
          if(this.issendoutsuccess == '1'){
              if(this.afterreqoutclear == '1'){
                  //清除当前送出的数据
                  this.BtnClear();
                  this.issendoutsuccess == '0';
              }
          }
          this.autoFocusBarcode();
      },

      // 自动识别接收科室 未选中 打印包条码
      auto_dept_nocheck_pageCodePrint() {
          let pagecode = this.hidpackagebarcode;
          let userno = this.$tool.getSession(this.$tool.loginuserno);
          if (pagecode != null && pagecode != "") {
              let sql = btoa(encodeURIComponent("select SampleCount as 标本数量, SendUser as 送出人, CONVERT(varchar,GETDATE(),120) as 打印时间,  PackageBarcode as 包条码号,  dc_dept.deptname as 接收部门,    RecLabGroupID as 接收工作组, bb.deptname as 送出部门,'" + this.combarcodecnt + "' as 单采标本数,'" + this.mixbarcodecnt + "' as 混检标本数,u.username as 创建者, comments as 备注,'" + this.samplingPos + "' as 采样点 from Req_Trans  left join dc_dept on Req_Trans.RecieveDept = dc_dept.deptno left join dc_dept bb on Req_Trans.senddept = bb.deptno left join secsysuser u on Req_Trans.createuser = u.userno where Req_Trans.PackageBarcode = '" + pagecode.trim() + "'"));
              jsObj.PrintCustomReport(this.packagestyleid, sql, userno, "打包条码样式", ""); // 正式打印模式
          } else {
              this.$message({
                  message: "请选择要打印的包条码！",
                  type: "warning",
              });
          }
          this.autoFocusBarcode();
      },

      // 清除事件
      BtnClear() {
          if (this.ck_auto_dept) {
              // 自动识别接收科室 选中
              let translist = this.$refs.trans_table.getSelectRecords();
              if (translist.length > 0) {
                  this.$rmConfirm({
                      type: "提示",
                      msg: "可能有未送出标本，是否清空当前界面数据？",
                      btn: {
                          confirmBtnText: "确 定",
                          cancelBtnText: "取 消",
                      },
                  })
                      .then(() => {
                          translist.forEach((element) => {
                              XE.remove(this.trans_data, (item) => item.recievedeptno == element.recievedeptno);
                              XE.remove(this.master_data, (item) => item.recievedeptno == element.recievedeptno);
                              XE.clear(this.master_data_show);
                              this.master_data_show = XE.clone(this.master_data, true);
                          });
                          this.maintotal = this.master_data.length;
                          this.specimen_number = this.master_data.length;
                          this.total = this.master_data_show.length;
                          this.rdysendtotal = 0;
                          this.barcode = "";
                          this.mixbarcodecnt = "0";
                          this.mixpeoplecnt = "0";
                          this.combarcodecnt = "0";
                          this.autoFocusBarcode();
                      })
                      .catch(() => {
                          this.$message({
                              type: "info",
                              message: "已取消删除",
                          });
                          this.autoFocusBarcode();
                      });
              } else {
                  this.$message({
                      message: "请选择要清除的记录！",
                      type: "warning",
                  });
                  this.autoFocusBarcode();
              }
          } else {
              this.$rmConfirm({
                  type: "提示",
                  msg: "可能有未送出标本，是否清空当前界面数据？",
                  btn: {
                      confirmBtnText: "确 定",
                      cancelBtnText: "取 消",
                  },
              })
                  .then(() => {
                      this.master_data = [];
                      this.master_data_show = [];
                      this.detail_data = [];
                      this.trans_data = [];
                      this.total = 0;
                      this.rdysendtotal = 0;
                      this.specimen_number = 0;
                      this.barcode = "";
                      this.hidpackagebarcode = "";
                      this.barcode = "";
                      this.mixbarcodecnt = "0";
                      this.mixpeoplecnt = "0";
                      this.combarcodecnt = "0";
                      this.autoFocusBarcode();
                  })
                  .catch(() => {
                      this.$message({
                          type: "info",
                          message: "已取消删除",
                      });
                      this.autoFocusBarcode();
                  });
          }
      },

      // 主数据行双击 删除事件
      delete_master_data(row, column, event, cell) {
          //
          var barcode = row.row.barcode;
          var recievedeptno = row.row.recievedeptno;
          this.$rmConfirm({
              type: "提示",
              msg: "是否删除条码号为【" + barcode + "】的样本记录？",
              btn: {
                  confirmBtnText: "确 定",
                  cancelBtnText: "取 消",
              },
          })
              .then(() => {
                  var traninfo = this.trans_data.filter((item) => item.recievedeptno == recievedeptno);
                  XE.remove(this.master_data, (item) => item.barcode == barcode);
                  XE.clear(this.master_data_show);
                  this.master_data_show = XE.clone(this.master_data, true);
                  if (traninfo[0].samplecount > 1) {
                      traninfo[0].samplecount = parseInt(traninfo[0].samplecount) - 1; // 样本数量 更新
                      var mainlist = this.master_data.filter((item) => item.recievedeptno == recievedeptno);
                      traninfo[0].last_barcode = mainlist[0].barcode;
                  } else {
                      XE.remove(this.trans_data, (item) => item.recievedeptno == traninfo[0].recievedeptno);
                  }

                  this.maintotal--;
                  this.specimen_number--;
                  if (row.row.ismixbarcode == "1") {
                      this.mixbarcodecnt--;
                      this.mixpeoplecnt = parseInt(this.mixpeoplecnt) - parseInt(row.row.mixcnt);
                  } else {
                      this.combarcodecnt--;
                  }

                  if (this.$refs.master_table.data.length > 0) {
                      var currow = this.$refs.master_table.data[0];
                      this.$refs.master_table.setCurrentRow(currow);
                      this.querydetail(currow);
                  } else {
                      var currow = this.$refs.trans_table.data[0];
                      this.$refs.trans_table.setCurrentRow(currow);
                      this.querytransdetail(currow);
                  }
              })
              .catch(() => {
                  this.$message({
                      type: "info",
                      message: "已取消删除",
                  });
              });
      },

      // 历史记录查询
      BtnHistoryQuery() {
          this.dialogHistoryTableVisible = true;
          this.startdt = new Date();
          this.enddt = new Date();
          //this.create_user = this.$tool.getSession(this.$tool.loginuserno);
          this.QueryHistoryData();
      },
      // 弹窗 查询按钮操作
      btnHistoryQuery() {
          this.QueryHistoryData();
      },
      // 历史数据查询
      QueryHistoryData() {
          this.historyloading = true;
          this.$tool
              .request({
                  url: "REQ/REQ1/REQ120",
                  method: "post",
                  data: {
                      action: "get_Historydata",
                      startdt: this.startdt,
                      enddt: this.enddt,
                      createuser: this.create_user,
                  },
              })
              .then((res) => {
                  this.historytableData = res.data;
                  this.historyloading = false;
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      // 历史包条码打印
      btnHistoryPrint() {
          let translist = this.$refs.hTable.getSelectRecords();
          if (translist.length > 0) {
              let userno = this.$tool.getSession(this.$tool.loginuserno);
              for (let i = 0; i < translist.length; i++) {
                  const element = translist[i];
                  if (element.packagebarcode != null && element.packagebarcode != "") {
                      //获取采样点
                      this.$tool
                          .request({
                              url: "REQ/REQ1/REQ120",
                              method: "post",
                              data: {
                                  action: "get_SamplingPos",
                                  packagebarcode: element.packagebarcode.trim(),
                              },
                          }).then((res) => {
                              var samplingPos = res.samplingPos;
                              let sql = btoa(encodeURIComponent("select SampleCount as 标本数量, SendUser as 送出人, CONVERT(varchar,GETDATE(),120) as 打印时间,  PackageBarcode as 包条码号,  dc_dept.deptname as 接收部门,    RecLabGroupID as 接收工作组, bb.deptname as 送出部门,cc.allcomcount as 单采标本数,cc.allmixcount as 混检标本数,u.username as 创建者, comments as 备注,'" + samplingPos + "' as 采样点 from Req_Trans left join dc_dept on Req_Trans.RecieveDept = dc_dept.deptno left join dc_dept bb on Req_Trans.senddept = bb.deptno left join secsysuser u on Req_Trans.createuser = u.userno left join (select '" + element.packagebarcode.trim() + "' as packagebrc,count(*) as allcount, sum(mixcount) as allmixcount, (count(*) - sum(mixcount)) as allcomcount from (select a.packagebarcode, (case when isnull(b.mixbarcode, '') = '' then 0 else 1 end) as mixcount from req_transdetail as a left join req_mixsample b on a.barcode = b.mixbarcode where PackageBarcode = '" + element.packagebarcode.trim() + "') c) cc on Req_Trans.packagebarcode = cc.packagebrc where Req_Trans.PackageBarcode = '" + element.packagebarcode.trim() + "'"));
                              jsObj.PrintCustomReport(this.packagestyleid, sql, userno, "打包条码样式", ""); // 正式打印模式
                              //jsObj.SetCustomPrintConfig(this.packagestyleid, sql, userno, "打包条码样式"); //设计模式
                          })
                          .catch((e) => {
                              this.$message.error(e);
                          });
                  }
              }
          } else {
              this.$message({
                  message: "请选择要打印的包条码！",
                  type: "warning",
              });
          }
      },
      senduserinfochange(code, name) {
          this.senduserinfoval = code;
      },
      loginUser() {
          //护工需要先登录程序
          this.$rm_Login({
              type: "用户登录验证",
              btn: {
                  confirmBtnText: "确定",
                  cancelBtnText: "取消",
              },
          })
              .then((res) => {
                  if (res.flag == "1") {
                      this.senduserinfoval = res.userid;
                      this.readonly = true;
                  } else {
                      //登录失败
                      this.senduserinfoval = "";
                      this.userinfoname = "";
                      this.readonly = true;
                  }
              })
              .catch((e) => {
                  this.txtbarcode = "请先双击登录程序后再操作";
                  this.readonly = true;
              });
      },
  },
};
</script>

<style scoped>
.pagetop {
  left: 0;
  right: 0;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.middle-left {
  position: absolute;
  top: 0px;
  bottom: 0px;
  width: 300px;
  left: 0px;
}

.middle-right {
  position: absolute;
  top: 0px;
  bottom: 0px;
  width: 300px;
  right: 0px;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table tr td:nth-child(1) {
  width: 80px;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.table1style tr td {
  padding: 0px 2px 1px 2px;
}
.el-input.is-disabled .el-input__inner {
  color: #FFFFFF !important;
}
</style>
